/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.webapp.component;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import vn.webapp.form.TeacherValidationForm;

/**
 *
 * @author Tonytran
 */
@Component
public class TeacherValidation implements Validator{
   private String Parten_EMAIL = "[safdsa[dsada";
   @Override
   public boolean supports(Class clazz) {
      return TeacherValidationForm.class.isAssignableFrom(clazz);
   }

   @Override
   public void validate(Object target, Errors errors) {
      TeacherValidationForm validationForm= (TeacherValidationForm)target;
      ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "Enter firstname.");     
      ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "Enter surname.");    
      if(validationForm.getEmail().matches(Parten_EMAIL)){
          ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "fuck."); 
      }

   }
}
